/**
 * 请求环境地址
 */
// const url_all = {
// 	"DEV":"http://47.108.195.251:12000"
// }

/**
 * 默认请求环境
 */
// let BASEURL = url_all['DEV']

// proxy path
let BASEURL = '/api'

export const request = (options = {}) => {
	return new Promise((resolve, rejects) => {
		handleRequest(options, resolve, rejects)
	})
}

// 发起请求
function handleRequest(options, resolve, reject) {
	let header;
	if (!options.url.includes('/auth/login')) {
		header = {
			'X-Token': uni.getStorageSync('token')
		}
	}
	uni.request({
		url: BASEURL + options.url,
		method: options.method,
		header,
		data: options.data,
		success: (response) => {
			return resolve(response.data)
		},
		fail: (fail) => {
			console.log('fail', fail)
			return reject(fail);
		}
	})
}